home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ubufox / chrome / ubufox.jar / content / pluginInstallerDatasource.js < prev    next >
Encoding:
Text File  |  2009-04-14  |  7.0 KB  |  186 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is Plugin Finder Service.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * IBM Corporation.
  18.  * Portions created by the IBM Corporation are Copyright (C) 2004-2005
  19.  * IBM Corporation. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Doron Rosenberg <doronr@us.ibm.com>
  23.  *   Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. const RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
  40. const PFS_NS = "http://www.mozilla.org/2004/pfs-rdf#";
  41.  
  42. function nsRDFItemUpdater(aClientOS, aChromeLocale){
  43.   this._rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
  44.                         .getService(Components.interfaces.nsIRDFService);
  45.   this._os = Components.classes["@mozilla.org/observer-service;1"]
  46.                        .getService(Components.interfaces.nsIObserverService);
  47.  
  48.   var app = Components.classes["@mozilla.org/xre/app-info;1"]
  49.                       .getService(Components.interfaces.nsIXULAppInfo);
  50.   this.appID = app.ID;
  51.   this.buildID = app.platformBuildID;
  52.  
  53.   this.clientOS = aClientOS;
  54.   this.chromeLocale = aChromeLocale;
  55.  
  56.   var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  57.                              .getService(Components.interfaces.nsIPrefBranch);
  58.   this.dsURI = prefBranch.getCharPref("pfs.datasource.url");
  59. }
  60.  
  61. nsRDFItemUpdater.prototype = {
  62.   checkForPlugin: function (aPluginRequestItem){
  63.     var dsURI = this.dsURI;
  64.     // escape the mimetype as mimetypes can contain '+', which will break pfs.
  65.     dsURI = dsURI.replace(/%PLUGIN_MIMETYPE%/g, encodeURIComponent(aPluginRequestItem.mimetype));
  66.     dsURI = dsURI.replace(/%APP_ID%/g, this.appID);
  67.     dsURI = dsURI.replace(/%APP_VERSION%/g, this.buildID);
  68.     dsURI = dsURI.replace(/%CLIENT_OS%/g, this.clientOS);
  69.     dsURI = dsURI.replace(/%CHROME_LOCALE%/g, this.chromeLocale);
  70.  
  71.     var ds = this._rdfService.GetDataSource(dsURI);
  72.     var rds = ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource)
  73.     if (rds.loaded)
  74.       this.onDatasourceLoaded(ds, aPluginRequestItem);
  75.     else {
  76.       var sink = ds.QueryInterface(Components.interfaces.nsIRDFXMLSink);
  77.       sink.addXMLSinkObserver(new nsPluginXMLRDFDSObserver(this, aPluginRequestItem));
  78.     }
  79.   },
  80.  
  81.   onDatasourceLoaded: function pfs_onDatasourceLoaded (aDatasource, aPluginRequestItem){
  82.     var container = Components.classes["@mozilla.org/rdf/container;1"].
  83.                   createInstance(Components.interfaces.nsIRDFContainer);
  84.     var resultRes = this._rdfService.GetResource("urn:mozilla:plugin-results:" + aPluginRequestItem.mimetype);
  85.     var pluginList = aDatasource.GetTarget(resultRes, this._rdfService.GetResource(PFS_NS+"plugins"), true);
  86.     var pluginInfos = new Array();
  87.   
  88.     container = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
  89.     try {
  90.       container.Init(aDatasource, pluginList);
  91.  
  92.       var children = container.GetElements();
  93.       // get the first item
  94.       while(children.hasMoreElements()) {
  95.  
  96.     var target;
  97.     var child = children.getNext();
  98.     if (child instanceof Components.interfaces.nsIRDFResource){
  99.       var name = this._rdfService.GetResource("http://www.mozilla.org/2004/pfs-rdf#updates");
  100.       target = aDatasource.GetTarget(child, name, true);
  101.     }
  102.  
  103.     try {
  104.       container.Init(aDatasource, target);
  105.       var target2 = null;
  106.       var children2 = container.GetElements();
  107.  
  108.       while (children2.hasMoreElements()) {
  109.         var child2 = children2.getNext();
  110.         if (child2 instanceof Components.interfaces.nsIRDFResource){
  111.           target2 = child2;
  112.         }
  113.  
  114.         var rdfs = this._rdfService;
  115.  
  116.         function getPFSValueFromRDF(aValue){
  117.           var rv = null;
  118.  
  119.           var myTarget = aDatasource.GetTarget(target2, rdfs.GetResource(PFS_NS + aValue), true);
  120.           if (myTarget)
  121.         rv = myTarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  122.  
  123.           return rv;
  124.         }
  125.  
  126.         var pluginInfo = {
  127.           name: getPFSValueFromRDF("name"),
  128.           pid: getPFSValueFromRDF("guid"),
  129.           version: getPFSValueFromRDF("version"),
  130.           IconUrl: getPFSValueFromRDF("IconUrl"),
  131.           desc: getPFSValueFromRDF("description"), 
  132.           homepage: getPFSValueFromRDF("homepage"),
  133.           XPILocation: getPFSValueFromRDF("XPILocation"),
  134.           XPIHash: getPFSValueFromRDF("XPIHash"),
  135.           InstallerShowsUI: getPFSValueFromRDF("InstallerShowsUI"),
  136.           manualInstallationURL: getPFSValueFromRDF("manualInstallationURL"),
  137.           requestedMimetype: getPFSValueFromRDF("requestedMimetype"),
  138.           licenseURL: getPFSValueFromRDF("licenseURL"),
  139.           needsRestart: getPFSValueFromRDF("needsRestart"),
  140.           fileHint: getPFSValueFromRDF("filehint")
  141.         };
  142.  
  143.         pluginInfos.push(pluginInfo);
  144.       }
  145.     }
  146.     catch (ex){}
  147.       }
  148.     }
  149.     catch (ex){}
  150.     
  151.     gPluginInstaller.pluginInfoReceived(pluginInfos);
  152.   },
  153.  
  154.   onDatasourceError: function pfs_onDatasourceError (aPluginRequestItem, aError){
  155.     this._os.notifyObservers(aPluginRequestItem, "error", aError);
  156.     gPluginInstaller.pluginInfoReceived(null);
  157.   },
  158. };
  159.  
  160. function nsPluginXMLRDFDSObserver(aUpdater, aPluginRequestItem){
  161.   this._updater = aUpdater;
  162.   this._item    = aPluginRequestItem;
  163. }
  164.  
  165. nsPluginXMLRDFDSObserver.prototype = 
  166.   _updater  : null,
  167.   _item     : null,
  168.  
  169.   // nsIRDFXMLSinkObserver
  170.   onBeginLoad: function(aSink){},
  171.   onInterrupt: function(aSink){},
  172.   onResume: function(aSink){},
  173.   onEndLoad: function(aSink){
  174.     aSink.removeXMLSinkObserver(this);
  175.     
  176.     var ds = aSink.QueryInterface(Components.interfaces.nsIRDFDataSource);
  177.     this._updater.onDatasourceLoaded(ds, this._item);
  178.   },
  179.   
  180.   onError: function(aSink, aStatus, aErrorMsg){  
  181.     aSink.removeXMLSinkObserver(this);   
  182.     this._updater.onDatasourceError(this._item, aStatus.toString());
  183.   }
  184. };
  185.